<template>
	<view class="content">
		<view class="top _df _jb _ac">
			<view class="img" @click="toPersonal">
				<image v-if="isLogin" :src="host + user.photo" mode=""></image>
				<image v-else src="@/static/img/mine/defalt.png" mode=""></image>
			</view>
			<view class="text" v-if="isLogin" @click="toPersonal">
				<view class="name" v-if="user.nickName!=null">
					{{user.nickName?user.nickName:'昵称'}}
				</view>
				<view class="name" v-else>
					完善个人信息
				</view>
				<view class="info _df _ac">
					{{user.sex}} {{user.age?user.age+'岁':''}} 
					<!-- <u-tag class="ml20" text="慢性病" :bg-color="tabBg" color="#fff" size="default" mode="dark" shape="circle" /> -->
				</view>
			</view>
			
			<view class="text" v-else>
				<view class="btn" @click="toLogin">立即登录</view>
			</view>
			<view class="setup" @click="toPersonal">
				<image src="@/static/img/mine/icon0.png" mode=""></image>
			</view>
		</view>
		
		<view class="watch-box" @click="towatchview">
			<image class="shuaxin" @click.stop="refresh" src="@/static/img/index/shuaxin.png" mode=""></image>
			<view class="img fl">
				<image src="@/static/img/mine/icon2.png" mode=""></image>
			</view>
			<view class="_df _ac" style="overflow: hidden;" v-if="deviceId == '' && !watchName">
				<!-- <view class="text" v-if="isJoin">
					<view class="state _df _ac">
						正在同步<u-loading mode="flower" size="34" color="#A18739"></u-loading>
					</view>
					
				</view> -->
				<view class="syncbtn" @click.stop="toaddsb">
					添加设备
				</view>
			</view>
			<view class="text" v-else style="overflow: hidden;">
				<view class="name">
					{{watchName}}
				</view>
				<view class="state _df">
					<!-- <view class="mr10">
						{{isJoin?'已连接':''}}
					</view>
					| -->
					<view class="_df _ac">
						电量:
						<!-- <u-loading v-if="!power" mode="flower" size="34"></u-loading> -->
						{{power}}
						 <span>%</span>
					</view>
				</view>
				<view class="syncbtn" @click.stop="syncFn">
					<!-- <view class="">
						
					</view> -->
					{{tbText}}
					<u-loading v-show="isRefresh" mode="flower" size="34"></u-loading>
				</view>
			</view>
			
		</view>
		<view class="con">
			<view class="box1">
				<view class="item _df _jb _ac" @click="toJf('/pages/tabbar/mine/integral/integral')">
					<view class="text">
						<view class="title">
							积分兑换
						</view>
						<view class="info">
							兑免费好礼
						</view>
					</view>
					<image class="img" src="@/static/img/mine/icon3.png" mode=""></image>
				</view>
				<view class="item item2 _df _jb _ac" @click="toJf('/pages/tabbar/mine/integral/medal')">
					<view class="text">
						<view class="title">
							我的勋章
						</view>
						<view class="info">
							查看更多
						</view>
					</view>
					<image class="img" src="@/static/img/mine/icon4.png" mode=""></image>
				</view>
			</view>
			<view class="box2">
				<view class="title-box _df _jb _ac">
					<view class="icon _df _jc _ac">
						<image class="img" src="@/static/img/mine/icon5.png" mode=""></image>
					</view>
					<view class="title">
						每日任务
					</view>
					<view class="time-box _df _ac" @click="timeShow = true" style="font-size: 28rpx;color: #999;">
						{{time}}
						<u-icon class="ml20" name="calendar" size="40" color="#7089DA"></u-icon>
					</view>
					
					<!-- <navigator url="/pages/tabbar/mine/activity-statistics">
						<view class="view">
							查看详情<u-icon class="ml20" name="arrow-right" color="#888" size="28"></u-icon>
						</view>
					</navigator> -->
					
				</view>
				<view class="week-box _df">
					<view class="item" v-for="(item,index) in dateList" :key="index" @click="dayChange(item,index)">
						<view class="week" :class="item.isActive ? 'active' : ''">
							{{item.week}}
						</view>
						<view class=""  style="text-align: center;font-size: 24rpx;color: #999;margin-bottom: 10rpx;">
							{{item.day.slice(8,10)}}
						</view>
						<view class="right">
							<view class="item item1">
								<u-circle-progress
									inactive-color="#e3edff"
									active-color="#4184ff" 
									:percent="item.list[1].percent>100?100:item.list[1].percent"
									border-width="6"
									width="72"
									bg-color="none"
									duration="1000"
								 >
									
								</u-circle-progress>
							</view>
							<view class="item item2">
								<u-circle-progress
									inactive-color="#fff4e2"
									active-color="#fcb23a" 
									:percent="item.list[0].percent>100?100:item.list[0].percent"
									border-width="6"
									width="52"
									duration="1000"
									bg-color="none"
								 >
									
								</u-circle-progress>
							</view>
							<view class="item item3">
								<u-circle-progress
									inactive-color="#e9f8f1"
									active-color="#6bce9e" 
									:percent="item.list[2].percent>100?100:item.list[2].percent"
									border-width="6"
									width="32"
									duration="1000"
									bg-color="none"
								 >
									
								</u-circle-progress>
							</view>
							
						</view>
					</view>
				</view>
				<view class="num-box _df _jb">
					<view class="left">
						<view class="item">
							<view class="name">
								今日冥想
							</view>
							<view class="info _df">
								<view class="num">{{hdData[1].time}}</view>
								/
								<view class="num2">{{hdData[1].missionTime||10}}</view>
								<view class="dw">
									次
								</view>
							</view>
						</view>
						<view class="item item2">
							<view class="name">
								今日正念
							</view>
							<view class="info _df">
								<view class="num">{{hdData[0].time}}</view>
								/
								<view class="num2">{{hdData[0].missionTime || 10}}</view>
								<view class="dw">
									次
								</view>
							</view>
						</view>
						
						<view class="item item3">
							<view class="name">
								今日呼吸
							</view>
							<view class="info _df">
								<view class="num">{{hdData[2].time}}</view>
								/
								<view class="num2">{{hdData[2].missionTime || 10}}</view>
								<view class="dw">
									次
								</view>
							</view>
						</view>
					</view>
					<view class="right">
						<view class="item item1">
							<u-circle-progress
								inactive-color="#e3edff"
								active-color="#4184ff" 
								:percent="hdData[1].time *10 > 100?100:hdData[1].time *10"
								border-width="30"
								width="330"
								duration="1000"
								bg-color="none"
							 >
								
							</u-circle-progress>
						</view>
						<view class="item item2">
							<u-circle-progress
								inactive-color="#fff4e2"
								active-color="#fcb23a" 
								:percent="hdData[0].time *10 > 100?100:hdData[0].time *10"
								border-width="30"
								width="250"
								bg-color="none"
								duration="1000"
							 >
								
							</u-circle-progress>
						</view>
						
						<view class="item item3">
							<u-circle-progress
								inactive-color="#e9f8f1"
								active-color="#6bce9e" 
								:percent="hdData[2].time *10 > 100?100:hdData[2].time *10"
								border-width="30"
								width="170"
								duration="1000"
								bg-color="none"
							 >
								
							</u-circle-progress>
						</view>
						
					</view>
				</view>
			</view>
			<view class="box3">
				<view class="item _df _ac _jb" hover-class="hover" v-for="(item,index) in menuList" :key="index" @click="toView(item)">
					<image class="img" :src="item.img" mode=""></image>
					<view class="title">
						{{item.title}}
					</view>
					<view class="info">
						{{item.value}}<u-icon class="ml15" name="arrow-right" color="#888" size="28"></u-icon>
					</view>
				</view>
				
			</view>
			<view class="box3">
				<view class="item _df _ac _jb" hover-class="hover" v-for="(item,index) in menuList2" :key="index" @click="clickFn(item,index)" v-if="item.show">
					<image class="img" :src="item.img" mode=""></image>
					<view class="title">
						{{item.title}}
					</view>
					<view class="info">
						{{item.value}}<u-icon class="ml15" name="arrow-right" color="#888" size="28"></u-icon>
					</view>
				</view>
				
			</view>
			<view class="btn-box">
				<u-button class="btn" @click="goExit" size="default" shape="circle" type="primary">退出登录</u-button>
				<!-- <u-button class="btn" :plain="true" @click="exit" size="default" shape="circle" type="primary">注销账号</u-button> -->
			</view>
		</view>
		<!-- <send-order ref="blue" @blueBack="blueBack"></send-order> -->
		<u-popup v-model="popshow" mode="center" border-radius="34" :closeable="true" width="90%" height="750rpx">
			<view class="popcon" style="height: 100%;padding: 0 30rpx;">
				<view class="ewm">
					<image :src="ewmUrl" mode=""></image>
				</view>
				<view class="text" style="padding: 0 40rpx;">
					分享二维码给朋友,在浏览器中扫描下载。
				</view>
				<view class="_df _jc">
					<u-button style="width: 100%;" type="primary" @click="savePic">保存图片</u-button>
				</view>
			</view>
		</u-popup>
		<u-calendar active-bg-color="#7089DA" v-model="timeShow" mode="date" @change="timeChange"></u-calendar>
	</view>
</template>

<script>
	import config from "@/utils/config.js";
	import moment from "moment";
	let timer;
	export default {
		data() {
			return {
				tabBg:'#5A64C5',
				dateList:[],
				time: moment().format('YYYY-MM-DD'),
				menuList:[
					// {
					// 	img:require('@/static/img/mine/notice-line.png'),
					// 	title:'每日提醒',
					// 	path:'/pages/tabbar/mine/warn'
					// },
					{
						img:require('@/static/img/mine/heart-line.png'),
						title:'健康检测',
						path:'/pages/tabbar/mine/health-set',
						value:'',
						show:true
					},
					// {
					// 	img:require('@/static/img/mine/login-line.png'),
					// 	title:'SOS紧急求救',
					// 	path:''
					// },
					{
						img:require('@/static/img/mine/share.png'),
						title:'分享无忧',
						path:'',
						value:'',
						show:true
					},
					{
						img:require('@/static/img/mine/team-line.png'),
						title:'关于无忧',
						path:'/pages/tabbar/mine/about',
						value:'',
						show:true
					},
					{
						img:require('@/static/img/mine/mIcon1.png'),
						title:'意见反馈',
						path:'/pages/setup/message',
						value:'',
						show:true
					},
					{
						img:require('@/static/img/mine/mIcon2.png'),
						title:'账号绑定',
						path:'/pages/setup/account/account',
						value:'',
						show:true
					},
				],
				menuList2:[
					{
						img:require('@/static/img/mine/mIcon5.png'),
						title:'系统设置',
						path:'/pages/tabbar/mine/keepTask',
						value:'',
						show:true
					},
					{
						img:require('@/static/img/mine/icon1.png'),
						title:'',
						path:'/pages/setup/news',
						value:'',
						show:false
					},
					{
						img:require('@/static/img/mine/mIcon3.png'),
						title:'检查更新',
						path:'',
						value:'',
						show:true
					},
					{
						img:require('@/static/img/mine/mIcon4.png'),
						title:'清理缓存',
						path:'',
						value:'',
						show:true
					},
					
				],
				popshow:false,
				isLogin:false,
				user:{},
				host:null,
				deviceId:'',
				notifyUuid:'',
				serviceId:'',
				writeId:'',
				watchName:'',
				power:'--',//电量
				bluedata:{},
				isJoin:false,
				dataParams:{
					totalSteps:0,//总计步
					totalHeat:0,//总卡路里
					totalDistance:0,//总距离
					totalSleep:0,//总睡眠(分钟)
					totalDeepSleep:0,//深睡（分钟）
					totalLightSleep:0,// 浅睡（分钟）
					currentHeartRate:0,//心率（次/分钟）
					currentFz:0,//舒张压
					currentSs:0,//收缩压
					currentBloodOxygen:0,//血氧饱和度
					currentPressure:0,///压力
					currentMet:0,///梅脱
					currentMai:0,///MAI
					currentTemp:0,//温度（0.1摄氏度）
					currentBloodSugar:0,//血糖（0.1）
					iswear:0,
					createTime:null,
					longitude:'',
					latitude:'',
					address:'',
				},
				orderDataList:[
					{
						name:'错误码',
						len:1,
						value:'',
						data:'',
						dataLen:0
						
					},
					{
						name:'电量百分比',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					
					
				],
				hdList:[],
				hdData:[
					{
						type:'1',
						time:0,
						total:10
					},
					{
						type:'2',
						time:0,
						total:10
					},
					{
						type:'3',
						time:0,
						total:10
					}
				],
				today:0,
				isRefresh:false,
				ewmUrl:require('@/static/img/mine/ewm.png'),
				activeTime:'',
				timeShow:false,
				firstTime:'',
				tbText:'同步',
				isTest:false
			};
		},
		watch:{
			isRefresh(v){
				this.isRefresh = v
			}
		},
		onShow() {
			this.getUser()
			this.getWatch()
			this.findWeekData()
			if(uni.$_getToken()){
				this.isLogin=true
			}
			this.getCacheSize()
			uni.$_addAccess(this)
			
			if(!uni.getStorageSync('isJoin')){
				this.tbText = '设备未连接'
			}else{
				if(uni.getStorageSync('isTesting')){
					this.isTest = true
					this.tbText = '压力测量中···'
				}else{
					this.isTest = false
					this.tbText = '同步'
				}
			}
		},
		onLoad() {
			this.host = config.host1
			if(uni.$_getSystem() != 'android'){
				// this.menuList2.find(item => item.title == '应用保活').show = false
			}
			// this.getDays()
		},
		methods:{
			refresh(){
				// this.getWatch()
				if(!uni.getStorageSync('isJoin')){
					this.tbText = '设备未连接'
				}else{
					if(uni.getStorageSync('isTesting')){
						this.isTest = true
						this.tbText = '压力测量中···'
					}else{
						this.isTest = false
						this.tbText = '同步'
					}
				}
				
			},
			timeChange(e){
				this.time = e.result.slice(0,10)
				
				this.findWeekData()
			},
			loginTip(e){
				if(!uni.$_getToken()){
					uni.$_publicModal(
					  "请先登录，是否前往？",
					  function () {
					    const u = "/pages/login/login?pathType=5";
					    uni.$_navFn("rto", u);
					  }
					);
					
				}else{
					uni.$_navFn("to", e);
				}
			},
			getCacheSize() {
				plus.cache.calculate((size) => {
					let new_size = size / (1024 * 1024)
					this.menuList2.forEach(item =>{
						if(item.title == '清理缓存'){
							if (new_size < 1024) {
								item.value = (new_size).toFixed(2) + 'MB'
							} else {
								item.value = (new_size / 1024).toFixed(2) + 'GB'
							}
						}
					})
					
				})
			},
			clearCache() { 
				plus.cache.clear(() => {
					uni.showToast({
						title: '清除成功!',
						icon: 'none',
						success: () => {
							this.menuList2.find(item => item.title == '清理缓存').value = '0.00MB'
						}
					})
				})
			},
			goSeting(){
				uni.openAppAuthorizeSetting({
					success: function () {
						console.log('打开系统设置页面成功');
					},
					fail: function () {
						console.log('打开系统设置页面失败');
					}
				});
			},
			clickFn(e,index){
				let that = this
				if(e.title == '系统设置'){
					if(uni.$_getSystem() == 'android'){
						uni.navigateTo({
							url:'/pages/tabbar/mine/keepTask'
						})
					}else{
						this.goSeting()
					}
				}else if(e.title == '清理缓存'){
					uni.$_publicModal(
					  "清理缓存可能导致数据异常，确定清理？",
					  function () {
					    that.clearCache()
					  }
					);
					
				}else if(e.title == '应用保活'){
					uni.navigateTo({
						url:'/pages/tabbar/mine/keepTask'
					})
				}
				else if(e.title == '检查更新'){
					uni.showToast({
						title:'应用上架后可使用',
						icon:'none'
					})
				}
				else{
					this.loginTip(e.path)
				}
			},
			goExit() {
				uni.$_publicModal('确定退出当前账号？', function() {
			// 		uni.removeStorage({
			// 			key: 'user',
			// 			success: function(res) {
			
			// 			}
			// 		});
					uni.removeStorage({
						key: 'token',
						success: function(res) {
			
						}
					});
					uni.$_navFn("too", "/pages/login/login?pathType=1");
				})
			},
			//下载海报，只在APP内有效
			savePic(){
				let imagePath = this.host + '/static/img/mine/ewm.png';
					uni.downloadFile({//下载
						url: imagePath, //图片下载地址
						success: res => {
							console.log(res);
							if (res.statusCode === 200) {
								uni.saveImageToPhotosAlbum({//保存图片到系统相册。
									filePath: res.tempFilePath,//图片文件路径
									success: function() {
										uni.showToast({
											title: '图片保存成功',
											icon: 'none',
										});
										that.popshow = false
									},
									fail: function(e) {
										console.log(e);
										uni.showToast({
											title: '图片保存失败',
											icon: 'none',
										});
									}
								});
							}
						}
					});
				},

			
			towatchview(){
				console.log(123)
				if(!uni.getStorageSync('isJoin')){
					this.tbText = '设备未连接'
				}else{
					if(uni.getStorageSync('isTesting')){
						this.isTest = true
						this.tbText = '压力测量中···'
						uni.showToast({
							title:'正在测量压力，请稍后重试',
							icon:'none',
							duration:1500
							
						})
					}else{
						this.isTest = false
						this.tbText = '同步'
						uni.navigateTo({
							url:'/pages/tabbar/mine/watch-view'
						})
					}
				}
				
			},
			toaddsb(){
				uni.reLaunch({
					url:'/pages/comA/bluetooth/bluetooth'
				})
			},
			getWatch(){
				let that = this;
				uni.$_get({
					url: "get-watch",
					that: that,
					success(res) {
						let _data = res.data;
						if(res.code == 0){
							if(_data){
								that.deviceId = _data.deviceId
								that.notifyUuid = _data.notifyUuid
								that.serviceId = _data.serviceId
								that.writeId = _data.writeId
								that.watchName = _data.name
							}else{
								// uni.showToast({
								// 	title:'设备未连接！'
								// })
							}
						}
						
					},
					fail(err) {
						
					},
				});
			},
			getCurrentTimeHex(format) {
			    // 获取当前时间的毫秒数
				let date = new Date()
				let year = 0+date.getFullYear().toString(16)
				let year1 =year.slice(0,2)
				let year2 =year.slice(2,4)
				let month = (date.getMonth() + 1).toString(16)
				let day = date.getDate().toString(16)
				let hour = date.getHours().toString(16)
				let minute = date.getMinutes().toString(16)
				let second = date.getSeconds().toString(16)
			    if(month.length==1){
					month = 0 + (date.getMonth() + 1).toString(16)
				}else{
					month = (date.getMonth() + 1).toString(16)
				}
				if(day.length==1){
					day = 0 + day
				}else{
					day = day
				}
				if(hour.length==1){
					hour = 0 + hour
				}else{
					hour = hour
				}
				if(minute.length==1){
					minute = 0 + minute
				}else{
					minute = minute
				}if(second.length==1){
					second = 0 + second
				}else{
					second = second
				}
				
				let timeOrder = year2+year1+month+day+hour+minute+second+'00'
			    // 将毫秒数转换为16进制字符串
			 
			    return timeOrder;	
			},
			syncFn(){
				if(this.isTest){
					return
				}else if(!uni.getStorageSync('isJoin')){
					this.toaddsb()
				}else{
					this.isRefresh = true
					//同步电量
					setTimeout(()=>{
						this.writeFn('da060000')
					},1000)
					//健康检测开关
					setTimeout(()=>{
						this.writeFn('da0e0600010101010101')
					},1000)
					//消息推送开关
					setTimeout(()=>{
						this.writeFn('da0c130001010101010101010101010101010101010101')
					},1500)
					
					// // //同步时间
					let timeOrder = 'da080800'+this.getCurrentTimeHex()
					setTimeout(()=>{
						this.writeFn(timeOrder)
					},2000)
					setTimeout(()=>{
						this.writeFn('da130200e001')
					},2500)
					// //设置心率检测间隔和范围指令0x31
					// setTimeout(()=>{
					// 	this.writeFn('da3106000101173b0141')
					// },4000)
				}
				
			},
			blueBack(e,ids){
				this.isJoin = e
				if(e){
					// this.startNotice()
					// setTimeout(()=>{
					// 	this.writeFn('da060000')
					// },1000)
				}else{
					this.$refs.blue.getWatch()
				}
			},
			writeFn(orderVal) {
				var that = this
				let crc = uni.$_getCrc_16_ibm(orderVal)
				let val = orderVal + crc
				console.log(val, '发送的指令')
				let buff = uni.$_hexStringToArrayBuffer(val)
				uni.writeBLECharacteristicValue({
					// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
					deviceId: that.deviceId,
					// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
					serviceId: that.serviceId,
					// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
					characteristicId: that.writeId, //第二步写入的特征值
					// 这里的value是ArrayBuffer类型
					value: buff,
					success: function(res) {
						//此时设备已接收到你写入的数据
						console.log("写入成功", res)
						uni.onBLECharacteristicValueChange(result => {
							// console.log("监听低功耗蓝牙设备的特征值变化", result);
							if (result.value) {
								let resHex = uni.$_ab2hex(result.value)
								console.log('设备返回手表信息', resHex)
								that.dataObj = uni.$_parse_blue_response(resHex, 2)
								clearInterval(timer)
								if(that.dataObj.Head == 'da' && that.dataObj.Cmd == "86" ) {
									that.dataToArr(that.dataObj.Data,that.orderDataList)
									
								}
								that.isRefresh = false
								
							}
						})
						
					},
					fail: function(err) {
						console.log(err)
						that.isRefresh = false
						clearInterval(timer)
						uni.hideLoading()
						
					},
					// complete: function() {
					// 	console.log("调用结束");
			
					// }
				})
			},
			
			//订阅蓝牙消息返回
			startNotice() {
				var that = this;
				uni.notifyBLECharacteristicValueChange({
					state: true, // 启用 notify 功能
					// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接 
					deviceId: this.deviceId,
					// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
					serviceId: this.serviceId,
					// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
					characteristicId: this.notifyUuid, //第一步 开启监听 notityid  第二步发送指令 write
					success(res) {
						//接收蓝牙返回消息
						// that.listenValueChange()
						console.log('接收蓝牙返回消息订阅成功')
						
						// setTimeout(()=>{
						// 	that.writeFn('da060000')
						// },1000)
					},
					fail(err) {
						console.log(err)
						uni.hideLoading()
					}
				})
			},
			dataToArr(dataList,orderDataList){
				orderDataList.forEach((item,index) =>{
					if(index == 0){
						item.dataLen = item.len
						item.value  = dataList.slice(0,item.dataLen)
					}else{
						item.dataLen = orderDataList[index-1].dataLen +orderDataList[index].len
						if(item.len>=2){
							let itemArr = dataList.slice(orderDataList[index-1].dataLen,item.dataLen).reverse()
							let str = itemArr.join('')
							item.value = str
							item.data = uni.$_hex2int(str)
						}else{
							let itemArr = dataList.slice(orderDataList[index-1].dataLen,item.dataLen)
							let str = itemArr.join('')
							item.value = str
							item.data = uni.$_hex2int(str)
							
						}
					}
				})
				// uni.showToast({
				// 	title:'获取成功！',
				// 	icon:'success'
				// })
				
				this.orderDataList = orderDataList
				this.power = this.orderDataList[1].data
				this.isRefresh = false
				console.log(this.orderDataList)
				uni.hideLoading()
			},
			addData(data){
				let that = this
				if(this.dataParams.iswear == 0) return
				// return
				this.$nextTick(()=>{
					uni.$_post({
						url: "addHealthData",
						that: that,
						params: that.dataParams,
						success(res) {
							console.log('数据提交成功')
							if(res.code == 0){
								that.getData()
							}else{
								uni.showToast({
									title: '添加失败',
									duration: 2000,
									icon:'error'
								});
							}
						},
						fail(err) {
							uni.showToast({
								title: '添加失败',
								duration: 1000,
								icon:'error'
							});	
							console.log(err)
						},
					});
				})
				
			},
			getUser() {
				let that = this;
				uni.$_get({
					url: "get-user",
					that: that,
					success(res) {
						let _data = res.data;
						if (res.code == 0) {
							that.user = _data
							that.menuList.find(item => item.title=='账号绑定').value = _data.phone
							// that.menuList2[0].value = _data.phone
						}
			
					},
					fail(err) {
			
					},
				});
			},
			toJf(e){
				this.loginTip(e)
			},
			//菜单跳转
			toView(e){
				if(e.title == '分享无忧'){
					// this.uniShare()
					this.popshow = true

				}else if(e.title == '健康检测'){
					if(uni.getStorageSync('isJoin')){
						if(uni.getStorageSync('isTesting')){
							this.isTest = true
							this.tbText = '压力测量中···'
							uni.showToast({
								title:'正在测量压力，请稍后重试',
								icon:'none',
								duration:1500
								
							})
						}else{
							this.isTest = false
							this.tbText = '同步'
							this.loginTip(e.path)
						}
					}else{
						uni.showToast({
							title:'请连接设备',
							icon:'none',
							duration:1500
						})
					}
					
					
				}
				else{
					this.loginTip(e.path)
				}
			},
			toSetup(){
				uni.navigateTo({
					url:'/pages/setup/setup'
				})
			},
			toLogin(){
				uni.redirectTo({
					url:'/pages/login/login?pathType=1'
				})
			},
			toPersonal(){
				this.loginTip('/pages/tabbar/mine/personal')
				
			},
			//周日期选择
			dayChange(e,index){
				// if(this.today<index+1) return
				this.dateList.map((item,i) =>{
					if(index == i){
						item.isActive = true
						this.hdData= item.list
					}else{
						item.isActive = false
					}
				})
			},
			getWeekDataList(data) {
				//根据日期获取本周周一~周日的年-月-日
				var weekList = [];
				var date = new Date(data);
				//判断本日期是否为周日，获取本周一日期
				if(date.getDay()=="0"){
					date.setDate(date.getDate() -6);
				}else {
					date.setDate(date.getDate() - date.getDay() + 1);
				}
				var myDate=date.getDate();
				var myMonth=date.getMonth() + 1;
				if(date.getDate()<10){
					myDate= '0'+ myDate;
				}
				if(date.getMonth() + 1<10){
					myMonth='0'+myMonth;
				}
				weekList.push(date.getFullYear() + "-" + myMonth+ "-" + myDate);
				// 获取周二以后日期
				for(var i=0;i<6;i++) {
					date.setDate(date.getDate() + 1);
					myDate=date.getDate();
					myMonth=date.getMonth() + 1;
					if(date.getDate()<10){
						myDate= '0'+ myDate;
					}
					if(date.getMonth() + 1<10){
						myMonth='0'+myMonth;
					}
					weekList.push(date.getFullYear() + "-" + myMonth+ "-" +myDate);
				}
				// console.log(weekList);
				return weekList
			},
			getDays(){
				
				let date = new Date(this.time);
				let weekList = this.getWeekDataList(this.time)
				let today = 0
				let dayOfWeek = date.getDay();
				if (dayOfWeek === 0) {
				  today = 0
				} else if (dayOfWeek === 1) {
				  today = 1
				} else if (dayOfWeek === 2) {
				  today = 2
				} else if (dayOfWeek === 3) {
				  today = 3
				} else if (dayOfWeek === 4) {
				  today = 4
				} else if (dayOfWeek === 5) {
				  today = 5
				} else {
				  today = 6
				}
				this.today = today
				let dateList = []
				let weeks = {
				  "6":'日',
				  "0":'一',
				  "1":'二',
				  "2":'三',
				  "3":'四',
				  "4":'五',
				  "5":'六',
				}
				this.hdList.map((item,index) =>{
					
					let dateObj = {
						week: weeks[index],
					    list:item.data,
						day:weekList[index],
						isActive:item.week==today?true:false,
					}
					
					dateList.push(dateObj);
					
				})
				let dateList2 = []
				let today2 = uni.$_momentTime(moment(),'YYYY-MM-DD')
				let list = [
					{
						type:'1',
						time:0,
						total:10
					},
					{
						type:'2',
						time:0,
						total:10
					},
					{
						type:'3',
						time:0,
						total:10
					}
				]
				weekList.map((item,index) =>{
					let dateObj = {
						week: weeks[index],
					    list:list,
						isActive:item==today2?true:false
					}
					dateList2.push(dateObj);
				})
				
				
				if(this.isLogin){
					this.dateList = dateList
					this.hdData= this.dateList[today-1].list
				}else{
					this.dateList = dateList2
				}
				console.log(this.dateList,666)
				// return dateObj
			
			},
			findWeekData(){
				let that = this
				let weekList = this.getWeekDataList(this.time)
				this.firstTime = weekList[0]
				uni.$_get({
					url: "findWeekData|" + this.firstTime,
					that: that,
					success(res) {
						let data = res.data;
						if(res.code == 0){
							data.map(item =>{
								item.data.map(item2 =>{
									item2.percent = Number((item2.time / item2.missionTime *100).toFixed(2))
								})
								
							})
							that.hdList = data
							// console.log(that.hdList)
							that.getDays()
						}else{
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: err.msg,
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
		}
		
	}
</script>

<style lang="scss" scoped>
	.popcon{
		.ewm{
			width: 400rpx;
			height: 400rpx;
			margin: 60rpx auto;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.text{
			font-size: 28rpx;
			color: #999;
			text-align: center;
			margin-bottom: 40rpx;
		}
	}
	.content{
		width: 100%;
		min-height: 100vh;
		padding: 120rpx 0 30rpx;
		box-sizing: border-box;
		background: #F2F6FE url(@/static/img/mine/myBg.png) no-repeat top center / 100% auto;
		.top{
			margin-bottom: 40rpx;
			padding: 0 40rpx;
			.img{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				margin-right: 30rpx;
				background: url("/static/img/mine/defalt.png") no-repeat center / cover;
				overflow: hidden;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.text{
				margin-right: auto;
				.name{
					height: 58rpx;
					line-height: 58rpx;
					font-size: 40rpx;
					color: #191919;
					font-family: $uni-font-family-Heavy;
				}
				.info{
					height: 54rpx;
					line-height: 54rpx;
					font-size: 28rpx;
					color: #333;
					font-family: $uni-font-family-Medium;
				}
				/deep/.u-tag{
					padding: 10rpx 20rpx;
				}
				.btn{
					width: 140rpx;
					height: 54rpx;
					border-radius: 27rpx;
					line-height: 54rpx;
					text-align: center;
					font-size: 24rpx;
					color: #333;
					background-color: #fbf3d1;
					margin-top: 20rpx;
				}
			}
			.setup{
				// padding-top: 20rpx;
				image{
					width: 42rpx;
					height: 40rpx;
				}
			}
		}
		.watch-box{
			margin: 0 30rpx;
			padding: 30rpx 50rpx;
			background: linear-gradient(-60deg,#fadd8a 0%, #fbf3d1 100%), #faf3d4;
			border-radius: 24rpx;
			z-index: 2;
			position: relative;
			overflow: hidden;
			.shuaxin{
				position: absolute;
				top: 30rpx;
				right: 30rpx;
				z-index: 2;
				width: 37rpx;
				height: 32rpx;
			}
			.img{
				width: 177rpx;
				height: 190rpx;
				margin-right: 45rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.text{
				padding-top: 14rpx;
				.name{
					height: 46rpx;
					line-height: 46rpx;
					font-size: 32rpx;
					color: #2F2C44;
					font-family: $uni-font-family-Bold;
				}
				.state{
					height: 46rpx;
					line-height: 46rpx;
					font-size: 26rpx;
					color: #A18739;
					font-family: $uni-font-family-Bold;
					margin-bottom: 20rpx;
				}
				
			}
			.syncbtn{
				// width: 160rpx;
				// min-width: 160rpx;
				// max-width: 280rpx;
				box-sizing: border-box;
				padding: 0 30rpx;
				display: inline-block;
				background: #7a5b3a;
				border-radius: 30rpx;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 26rpx;
				color: #FFFFE8;
				text-align: center;
				font-family: $uni-font-family-Bold;
			}
		}
		.con{
			padding: 150rpx 30rpx 60rpx;
			background-color: #F2F6FE;
			border-radius: 30rpx 30rpx 0 0;
			margin-top: -120rpx;
			.box1{
				margin-bottom: 35rpx;
				display: grid;
				grid-template-columns: 1fr 1fr;
				grid-column-gap: 30rpx;
				.item{
					padding: 20rpx 30rpx 20rpx 40rpx;
					height: 110rpx;
					background: #ffffff;
					border-radius: 24rpx;
					.text{
						.title{
							font-size: 34rpx;
							color: #D89A36;
							margin-bottom: 2rpx;
							font-family: $uni-font-family-Heavy;
						}
						.info{
							font-size: 24rpx;
							color: #686868;
							font-family: $uni-font-family-Medium;
						}
						
					}
					.img{
						width: 76rpx;
						height: 70rpx;
					}
				}
				.item2{
					.text{
						.title{
							color: #7580E8;
						}
					}
					
				}
			}
			.box2{
				padding: 40rpx 30rpx;
				background-color: #fff;
				border-radius: 24rpx;
				margin-bottom: 30rpx;
				.title-box{
					margin-bottom: 30rpx;
					.icon{
						border-radius: 15rpx;
						width: 50rpx;
						height: 50rpx;
						background-color: #669dff;
						.img{
							height: 30rpx;
							width: 30rpx;
						}
					}
					.title{
						font-size: 30rpx;
						color: #191919;
						font-family: $uni-font-family-Bold;
						margin: 0 auto 0 24rpx;
					}
					.view{
						font-size: 26rpx;
						color: #888;
						font-family: $uni-font-family-Medium;
					}
				}
				.week-box{
					margin-bottom: 40rpx;
					.item{
						flex: 1;
						justify-content: center;
						.week{
							width: 54rpx;
							height: 34rpx;
							font-size: 24rpx;
							color: #000;
							border-radius: 15rpx;
							background: none;
							transition: 0.3s ease;
							margin:  0 auto 15rpx;
							text-align: center;
							font-family: $uni-font-family-Heavy;
						}
						.day{
							font-size: 28rpx;
							color: #111;
							font-family: $uni-font-family-Heavy;
						}
						.right{
							position: relative;
							width: 72rpx;
							height: 72rpx;
							margin: 0 auto;
							.item{
								width: 100%;
								height: 100%;
								text-align: center;
								position: absolute;
								top: 0;
								left: 0;
								transform-origin: center center;
								display: flex;
								justify-content: center;
								align-items: center;
								
							}
							
						}
						.active{
							color: #fff;
							background: #7089da;
						}
					}
				}
				.num-box{
					padding-top: 30rpx;
					border-top: 1rpx solid #f0f0f0;
					.left{
						.item{
							margin-bottom: 30rpx;
							padding-left: 15rpx;
							.name{
								height: 42rpx;
								line-height: 42rpx;
								font-size: 28rpx;
								font-family: $uni-font-family-Heavy;
								color: #0c6cfe;
								padding-left: 20rpx;
								margin-bottom: 8rpx;
								position: relative;
								&:before{
									display: block;
									content: '';
									width: 6rpx;
									height: 20rpx;
									background-color: #0c6cfe;
									position: absolute;
									left: 0;
									top: 50%;
									margin-top: -10rpx;
								}
							}
							.info{
								height: 60rpx;
								line-height: 60rpx;
								font-size: 30rpx;
								font-family: $uni-font-family-Bold;
								color: #b0b0b0;
								.num{
									font-size: 54rpx;
									color: #000;
									margin-right: 6rpx;
									line-height: 50rpx;
								}
								.num2{
									font-size: 32rpx;
									margin: 0 6rpx;
								}
								.dw{
									font-size: 24rpx;
									margin-left: 6rpx;
									font-family: $uni-font-family-Medium;
								}
							}
						}
						.item2{
							.name{
								color: #fbaf32;
								&:before{
									background-color: #fbaf32;
								}
							}
							
						}
						.item3{
							.name{
								color: #6ace9e;
								&:before{
									background-color: #6ace9e;
								}
							}
							
						}
					}
					.right{
						position: relative;
						width: 330rpx;
						height: 330rpx;
						margin-top: 30rpx;
						.item{
							width: 100%;
							height: 100%;
							text-align: center;
							// transform: rotate(180deg);
							position: absolute;
							top: 0;
							left: 0;
							transform-origin: center center;
							// transform: rotate(-90deg);
							display: flex;
							justify-content: center;
							align-items: center;
							
						}
					}
				}
			}
			.box3{
				padding: 30rpx 0;
				background-color: #fff;
				border-radius: 24rpx;
				margin-bottom: 30rpx;
				.item{
					padding: 0 40rpx;
					height: 100rpx;
					.img{
						width: 36rpx;
						height: 36rpx;
					}
					.title{
						font-size: 30rpx;
						color: #000;
						margin: 0 auto 0 30rpx;
						font-family: $uni-font-family-Bold;
					}
					.info{
						font-size: 24rpx;
						color: #aaa;
					}
				}
				
				
			}
			
			
			.btn-box{
				width: 100%;
				box-sizing: border-box;
				/deep/.u-btn--primary{
					background-color: #6387FF;
					border-color: #6387FF;
				}
			}
		}
	}
</style>
